package cn.yunhe.Action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import cn.yunhe.Dao.BookDao;
import cn.yunhe.Dao.Impl.BookDaoImpl;
import cn.yunhe.entity.Book;
import cn.yunhe.util.RepAction;


public class BookAction extends RepAction{
	private String name;
	private String zuozhe;
	private String banshe;
	private double shoujia;
	private int kucun;
	private String tupian;
	
	
	public String getAll(){
		BookDao bd = new BookDaoImpl();
		List<Book> list = bd.getAll();
		HttpServletRequest hsr = RepAction.getRequest();
		hsr.setAttribute("list", list);
		return "chenggong";
	}
	
	
	
	public String addBook() throws Exception {
		BookDao bd= new BookDaoImpl();
		List<Book> list = bd.getAll();
		Book b = new Book();
		b.setName(name);
		b.setAuthor(zuozhe);
		b.setPress(banshe);
		b.setPrice(shoujia);
		b.setStock(kucun);
		b.setPhone(tupian);
		String str = "";
		for (int i = 0; i < list.size(); i++) {
			if(list.get(i).getName().equals(name)){
				str = "false";
				break;
			}else{
				str = "success";
			}
		}
		
		if(str.equals("success")){
			bd.addBook(b);
		}
		return str;
	}
	
	
	public String del() throws Exception {
		
		int id = Integer.parseInt(getRequest().getParameter("id"));
		BookDao bd = new BookDaoImpl();
		int del = bd.delBook(id);
		if(del>0){
			return "success";
		}else{
			return "error";
		}
		
	}
	
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getZuozhe() {
		return zuozhe;
	}
	public void setZuozhe(String zuozhe) {
		this.zuozhe = zuozhe;
	}
	public String getBanshe() {
		return banshe;
	}
	public void setBanshe(String banshe) {
		this.banshe = banshe;
	}

	public double getShoujia() {
		return shoujia;
	}

	public void setShoujia(double shoujia) {
		this.shoujia = shoujia;
	}

	public int getKucun() {
		return kucun;
	}

	public void setKucun(int kucun) {
		this.kucun = kucun;
	}

	public String getTupian() {
		return tupian;
	}
	public void setTupian(String tupian) {
		this.tupian = tupian;
	}
	
	
}
